require.config({
	shim: {	　　　　　　
		"bootstrap": {	// bootstrap依赖jquery库
			deps: ['jquery'],
			exports: 'bootstrap'
		},
		'handlebars': {　　　　　　　　
			exports: 'Handlebars'　　　　　　
		},
		"user": {
			deps: ['modal_template']
		}　　　　
	},
	paths: {　　　　　　
		//工具模块
		'less': 'tools/less.min',
		'jquery': 'tools/jquery.min',
		'bootstrap': 'tools/bootstrap.min',
		'handlebars': 'tools/handlebars',

		//配置模块
		'config': './config',
		"appConfig":"./appConfig",

		'top_bar': 'modules/top_bar',
		'problem': 'modules/problem',
		'ask': 'modules/ask',
		'modal_template': 'modules/modal_template',
		'cookie': 'modules/cookie',
		'check_log': 'modules/check_log',
		'login': 'modules/login',
		'other_log': 'modules/login',
		'reg': 'modules/reg',
		'user': 'modules/user',　　
	}
});
/************************************header***************************************/
//加载顶栏top_bar模块
require(['top_bar'], function(top_bar){
	top_bar();
});
/************************************content***************************************/
require(['jquery','handlebars','appConfig','cookie','less'], function ($,Handlebars,appConfig,cookie){
	require(['bootstrap'], function(){
		//alert('123asas')
	});
	//调整top_bar宽度为浏览器可视区宽度，让其不会因遮罩窗的弹出而抖动
	$('.fixed_div').css('width', $(window).width());
	$(window).resize(function(){
		//调整fixed_div的宽度为可视区的宽度
		$('.fixed_div').css('width', $(window).width());
	});
	var testData={
		breadcrumb:[
			{
				title:"图库",href:"gallery.html"
			},
			{
				title:"高分考卷"
			}
		],
		cat_list:[
			{
				href:"galleryTextSub.html",
				title:"清华美院高分考卷",
				date:"2014-12-1"
			},
			{
				href:"galleryTextSub.html",
				title:"中央美院高分考卷",
				date:"2014-12-1"
			},
			{
				href:"galleryTextSub.html",
				title:"广州美院高分考卷",
				date:"2014-12-1"
			},
		]
	};
	$(document).ready(function(){
		Handlebars.registerHelper("lastOne",function(index,length,options){

			if(index==length-1){
				return options.fn(this);
			}else{
				return options.inverse(this);
			}
		});//注册一个用于判断是否是某数组最后一个元素的helper
		fetchData();
		
	});
	function handlebarsRender(tplSelector,destSelector,data){
		//用jquery获取模板
		var source   = $(tplSelector).html();
		//预编译模板
		var template = Handlebars.compile(source);
		//匹配json内容
		var html = template(data);
		//输入模板
		$(destSelector).html(html);
	};
	function fetchData(){
		var url=window.location.search;
		var equalIndex=url.indexOf("=");
		var classId=url.substring(equalIndex+1);
		$.ajax({
			url:appConfig.host+"/api/classification/"+classId+"/list",
			success:function(d){
				console.log(d);
				handlebarsRender("#list",".container",d);
			}
		});
	}

});
